#ifndef __MINT_TYPES_H__
#define __MINT_TYPES_H__

#ifdef __cplusplus
extern "C" {
#endif

typedef signed char 				int8;
typedef signed short				int16;
typedef signed int					int32;
typedef signed long int				int64;

typedef unsigned char 				uint8;
typedef unsigned short				uint16;
typedef unsigned int				uint32;
typedef unsigned long int			uint64;

typedef volatile signed char 		vint8;
typedef volatile signed short		vint16;
typedef volatile signed int			vint32;
typedef volatile signed long int	vint64;

typedef volatile unsigned char 		vuint8;
typedef volatile unsigned short		vuint16;
typedef volatile unsigned int		vuint32;
typedef volatile unsigned long int	vuint64;

typedef uint8	byte;
typedef uint16	word;
typedef uint32	dword;
typedef uint64	qword;

typedef int32	Result;
typedef uint64	BigTime;
typedef uint32	Size;
typedef int32	Offset;
typedef uint32	Address;

#ifndef __cplusplus
typedef uint8	bool
#define false	(0)
#define true	(1)
#endif

#ifndef null
#define null (0)
#endif

#ifndef NULL
#define NULL (0)
#endif

#define ROUND_UP(a,b)			(((a)+((b)-1))&~((b)-1))
#define ROUND_DOWN(a,b)			(((a)/(b))*(b))

#define MIN(a,b)				((a)<(b)?(a):(b))
#define MAX(a,b)				((a)>(b)?(a):(b))

#define FLAG_ADD(a,b)			((a)|(b))
#define FLAG_REMOVE(a,b)		((a)&~(b))
#define FLAG_PRESENT(a,b)		(((a)&(b))==(b))
#define FLAG_ANY_PRESENT(a,b)	(((a)&(b))!=0)
#define FLAG_SET(a,b)			((a)|=(b))
#define FLAG_CLEAR(a,b)			((a)&=~(b))

#define BIT_ADD(a,b)			FLAG_ADD((a),(1<<(b)))
#define BIT_REMOVE(a,b)			FLAG_REMOVE((a),(1<<(b)))
#define BIT_PRESENT(a,b)		FLAG_PRESENT((a),(1<<(b)))

#define UNUSED(x)				((void)(x))
#define TOUCH(x)				UNUSED(x)

#define ARRAY_SIZE(x)			(sizeof(x)/sizeof(x[0]))

#ifdef __GCC__
#define _PACKED		__attribute__((packed))
#define _ALIGN(x)	__attribute__((aligned (x)))
#else
#define _PACKED
#define _ALIGN(x)
#endif

typedef char * Args;
#define Args_GetSize( Type ) ROUND_UP( sizeof(Type), sizeof(int) )
#define Args_Start( args, start )  ( (args) = ( (Args)(&start) + Args_GetSize( (start) ) ) )
#define Args_End( args )  ( (void)( (args) = 0 ) )
#define Args_GetArg( args, Type ) ( ( (args) = (args) + Args_GetSize(Type) ), *( (Type *)( (args) - Args_GetSize(Type) ) ) )

#ifdef __cplusplus
}
#endif

#endif // __MINT_TYPES_H__
